/**
 * 
 */
package com.wubo.sec.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @author WuBo
 * @CreateDate 2010-11-9
 * @version 1.0.01
 */
class ConfigContextImpl extends ConfigContext {
	
	private Properties prop = new Properties();
	
	public ConfigContextImpl(InputStream is) throws IOException {
		try{
			prop.load(is);
		}finally{
			is.close();
		}
	}

	@Override
	public String getValue(String key) {
		return prop.getProperty(key);
	}
	
	@Override
	public <T> T getValue(String key, Class<T> type) {
		return ConfigUtils.getValue(prop.getProperty(key), type);
	}
	
	@Override
	public Map<String, String> getValues(String keyPrefix) {
		Map<String, String> resultMap = new HashMap<String, String>();
		Enumeration<?> em = prop.propertyNames();
		while(em.hasMoreElements()){
			String key = (String) em.nextElement();
			if(key.startsWith(keyPrefix)){
				resultMap.put(key, prop.getProperty(key));
			}
		}
		return resultMap;
	}
}
